package com.second.app.thread.p_c_callwait;

/**
 * @Author soul yzg
 * @Date 2021/1/26 7:06
 * 努力学习 天天进步
 */
public class Produce {
    private String lock;

    public Produce(String lock){
        this.lock =lock;
    }
    public  void setValue(){
        try {
            synchronized (lock){
                if(!ValueObject.getValue().equals("")){
                    System.out.println("生产者"+Thread.currentThread().getName()+":WAITING了");
                    lock.wait();
                }
                System.out.println("生产者"+Thread.currentThread().getName()+":RUNNABLE");
                //value为空,生成线程设置value,通知消费线程消费。
                ValueObject.setValue(System.currentTimeMillis()+"_"+System.nanoTime());
                lock.notifyAll();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
